//
//  PassworldViewController.m
//  ios-test
//
//  Created by Apple -11 on 15/10/21.
//  Copyright (c) 2015年 Apple -11. All rights reserved.
//

#import "PassworldViewController.h"
#import "goodsViewController.h"
#import "ICSDrawerController.h"
#import "MenuViewController.h"
#import "PassworldViewController.h"
@interface PassworldViewController ()

@end

@implementation PassworldViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.passswordArr=[NSMutableArray array];
    self.password=[NSMutableString string];
    
    user1=[NSUserDefaults standardUserDefaults];
    passwordUser=[NSUserDefaults standardUserDefaults];
    
    view1.backgroundColor=[UIColor whiteColor];
    view2.backgroundColor=[UIColor whiteColor];
    view3.backgroundColor=[UIColor whiteColor];
    view4.backgroundColor=[UIColor whiteColor];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(IBAction)tapButton:(id)sender{
    UIButton *button=sender;
    [self.passswordArr addObject:[NSNumber numberWithInteger:button.tag]];
    
    if (self.passswordArr.count==1) {
        view1.backgroundColor=[UIColor lightGrayColor];
    }else if (self.passswordArr.count==2){
        view2.backgroundColor=[UIColor lightGrayColor];
    }
    else if (self.passswordArr.count==3){
        view3.backgroundColor=[UIColor lightGrayColor];
    }else if (self.passswordArr.count==4){
        view4.backgroundColor=[UIColor lightGrayColor];
        [self check];
    }
    
}
-(IBAction)deleteButton:(id)sender{
    
    //[self.passswordArr removeObject:[NSNumber numberWithInteger:self.passswordArr.count]];
    [self.passswordArr removeLastObject];
    
    if (self.passswordArr.count==0){
        view1.backgroundColor=[UIColor whiteColor];
        self.passswordArr=[NSMutableArray array];
    }
    else if (self.passswordArr.count==1) {
        view2.backgroundColor=[UIColor whiteColor];
    }else if (self.passswordArr.count==2){
        view3.backgroundColor=[UIColor whiteColor];
    }else if (self.passswordArr.count==3){
        view4.backgroundColor=[UIColor whiteColor];
    }
    
}
-(void)check{
    for(id pass in self.passswordArr){
        //[self.password stringByAppendingFormat:@"%@",pass];
        [self.password appendString:[pass stringValue]];
    }
    if ([self.password isEqualToString:[passwordUser objectForKey:@"pass"]]) {
        goodsViewController *root=[[goodsViewController alloc]init];
        MenuViewController *colorsVC = [[MenuViewController alloc] init];
        ICSDrawerController *drawer = [[ICSDrawerController alloc] initWithLeftViewController:colorsVC
                                                                                 centerViewController:root];
            [self presentViewController:drawer animated:YES completion:nil];
    }else{
        UIAlertView *alter=nil;
        alter=[[UIAlertView alloc]initWithTitle:@"警告！！！！" message:@"密码错误" delegate:nil cancelButtonTitle:@"close" otherButtonTitles:nil, nil];
        [alter show];
        view1.backgroundColor=[UIColor whiteColor];
        view2.backgroundColor=[UIColor whiteColor];
        view3.backgroundColor=[UIColor whiteColor];
        view4.backgroundColor=[UIColor whiteColor];
        [self.passswordArr removeAllObjects];
        self.passswordArr=[NSMutableArray array];
        self.password=[NSMutableString string];
    }

}
@end
